﻿using System.Windows.Controls;
using nRoute.Components;
using nRoute.Samples.OfficerXcel.Model;

namespace nRoute.Samples.OfficerXcel.Views
{
    public partial class WorksheetView : UserControl
    {
        private readonly ValueRelay _currentColumnHeaderValueRelay;

        public WorksheetView()
        {
            InitializeComponent();

            // this sets up to update the relay whenever the column changes
            _currentColumnHeaderValueRelay = (ValueRelay)this.Resources["CurrentColumnHeaderValueRelay"];

            dataGrid.CurrentCellChanged += (s, e) =>
                _currentColumnHeaderValueRelay.Value = dataGrid.CurrentColumn != null ?
                dataGrid.CurrentColumn.Header.ToString() : null;

            // set up the value converter
            this.SetRelayConverter<Worksheet, bool>("WorksheetNotNullConverterRelay", (w) => w != null);

        }
    }
}
